package com.example.tabbar.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.tabbar.databinding.ItemRoomDataBinding
import com.junray.usermangement.room.bean.RoomMeasurementData


// 房间下所有点位的数据适配器
class RoomDataAdapter: RecyclerView.Adapter<RoomDataAdapter.ViewHolder>() {
    private var items: MutableList<RoomMeasurementData> = ArrayList()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = ItemRoomDataBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = items[position]
        holder.locationName.text = item.samplingLoc
        holder.time.text = item.startTime + " - " + item.endTime
        holder.flowRate.text = "流量：" + item.flow.toString()+"L/min"
        holder.group.text = "分组：" + item.groupName
    }

    override fun getItemCount(): Int {
        return items.size ?: 0
    }

    fun setItems(items: List<RoomMeasurementData>?) {
        this.items.clear()
        if (items != null) {
            this.items.addAll(items)
            notifyDataSetChanged()
        }
    }


    class ViewHolder(binding: ItemRoomDataBinding)
        : RecyclerView.ViewHolder(binding.root) {
        var locationName = binding.locationName
        var time:TextView = binding.time
//        var samplingTime :TextView = binding.sampleTime
        var sampleVolume:TextView = binding.sampleVolume
        var group :TextView = binding.groupData
        var standard :TextView = binding.standardData
        var flowRate :TextView = binding.flowData
        var airType :TextView = binding.airTypeData
        var recipe :TextView = binding.recipeData
        var value03 :TextView = binding.zeroThree
        var value05 :TextView = binding.zeroFive
        var value1 :TextView = binding.oneData
        var value2 :TextView = binding.twoData
        var value3 :TextView = binding.threeData
        var value5 :TextView = binding.fiveData

//        var result :ImageView= binding.results
    }

}